<?php

namespace App\Controller;

use App\Utils\Msg;
use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\Snowflake\IdGeneratorInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ResponseInterface;

#[AutoController]
class TestController extends AbstractController
{
    public function ws(): ResponseInterface
    {
        $msgId = '';
        try {
            $generator = $this->container->get(IdGeneratorInterface::class);
            $msgId = $generator->generate();
        } catch (NotFoundExceptionInterface|ContainerExceptionInterface $e) {
        }
        $UserEntryCmd = Msg::Create('UserEntryCmd', [
            'app_user_id' => $this->request->post('app_user_id'),
            'device_id' => $this->request->post('device_id'),
            'match_id' => $this->request->post('match_id')
        ]);

        $UserHeartbeatCmd = Msg::Create('UserHeartbeatCmd', []);

        $UserSendMessageCmd = Msg::Create('UserSendMessageCmd', [
            'msg_id' => $msgId,
            'msg_type' => 'text',
            'msg_data' => $this->request->post('msg_data'),
        ]);
        return $this->apiReturn(200, 'succ', ['$UserEntryCmd' => base64_encode($UserEntryCmd), '$UserHeartbeatCmd' => base64_encode($UserHeartbeatCmd), '$UserSendMessageCmd' => base64_encode($UserSendMessageCmd)]);
    }
}